from flask import render_template

# from application.views.api.callback import callback
from application.views.backe_data_reload import back
from application.views.course import course_blue
from application.views.tcourse import tcourse_blue
from create_app import create_flask
from flask import request
import requests
from application.views.user import user_blue

app = create_flask()

app.register_blueprint(user_blue, url_prefix='/user')
app.register_blueprint(back, url_prefix='/back')
# app.register_blueprint(callback, url_prefix='/callback')
app.register_blueprint(course_blue, url_prefix='/course')
app.register_blueprint(tcourse_blue, url_prefix='/tcourse')


@app.route('/', methods=['POST'])
def index():
    data = request.json
    url = "https://oapi.dingtalk.com/robot/send?access_token=c42ae971590b607310e128b490a8aef9119c33929f48d944bf620ca9cf8c2271"
    ret = requests.post(url, json={
        "msgtype": "markdown",
        "markdown": {
            "title": "监控",
            "text": f"""#### 监控通知 \n
> cpu {data['cpu_info']}\n
> 内存总量 {data['total_memory']}G\n
> 已用内存 {int(data['used_memory'])}\n
@17611406668"""
        },
        "at": {
            "atMobiles": [
                "17611406668"
            ],
            "atUserIds": [
                "vqt_2ayf8q6bb"

            ],
            "isAtAll": False
        }
    })
    print(ret.json())
    return "asdf"



@app.route('/player', methods=['GET'])
def Film_Play():
    return render_template('player.html', movie={'file': 'vip.mp4', 'title': '???'})


@app.route('/edit', methods=['POST'])
def edit_stxt():
    print(request.json)
    return "afgasdf"




if __name__ == '__main__':
    print(app.url_map)
    app.run(host='0.0.0.0', port=8000)
